package hanjia;

/**
 * Description:
 * Author:    Dane
 * CreateTime:2025/2/12-下午3:20
 * Since  :   1.0
 * Version:   1.0
 */
public class LeetCode701 {

    public TreeNode insertIntoBST(TreeNode root, int val) {

        if (root==null){
            return new TreeNode(val);
        }
        TreeNode pre=null;
        TreeNode temp=root;
        while (temp!=null){
            pre=temp;
            if (val>temp.val){
                temp=temp.right;
            }else {
                temp=temp.left;
            }
        }
        if (val>pre.val){
            pre.right=new TreeNode(val);
        }else {
            pre.left=new TreeNode(val);
        }
        return root;



    }

}
